import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/view/HomeView.vue'
import ClassifyView from '@/view/ClassifyView.vue'
import CommunityView from '@/view/CommunityView.vue'
import SubscriptionView from '@/view/SubscriptionView.vue'
import RankingListView from '@/view/RankingListView.vue'
import NewFile from '@/view/NewFile.vue'
import LooplistView from '@/view/LooplistView.vue'

// import TestView from '@/view/TestView.vue'

const routers = [
    {
        path: '/',
        name: 'home',
        component: HomeView,
        meta: { title: '拾云壁纸', index: "1-1" }
    }, {
        path: '/classify',
        name: 'classify',
        component: ClassifyView,
        meta: { title: '分类', index: "1-2" }
    }, {
        path: '/community',
        name: 'community',

        component: CommunityView,
        meta: { title: '社区', index: "1-3" }
    }, {
        path: '/subscription',
        name: 'subscription',
        component: SubscriptionView,
        meta: { title: '订阅', index: "1-4" }
    }, {
        path: '/rankingList',
        name: 'rankingList',
        component: RankingListView,
        meta: { title: '榜单', index: "1-5" }
    },

    {
        path: '/newFile',
        name: 'newFile',
        title: '项目解说',
        component: NewFile, 
        meta: { title: '项目解说', index: "1-6" }
    },

    {
        path: '/looplist',
        name: 'looplist',
        title: '榜单测试',
        component: LooplistView,
        meta: { title: '榜单测试', index: "1-7" }
    }

    // {
    //     path: '/test',
    //     name: 'test',
    //     title: '测试',
    //     component: TestView, meta: { title: '测试', index: "1-5" }
    // }
]



const router = createRouter({
    history: createWebHistory(),
    routes: routers
})

// 路由守卫
router.beforeEach((to, from, next) => {
    // to.meta.title && (document.title = to.meta.title);

    if (to.meta && to.meta.index) {
        console.log('Page Index:', to.meta.pageIndex);
        console.log("title:", to)
        //标题设置成
        document.title = to.meta.title + ' - 拾云壁纸'

    }
    next();
});
export default router